<template>
    <div>
        <div>
            账号:
            <input type="text" v-model="name">
        </div>
        <div>
            密码:
            <input type="text" v-model="pass">
        </div>
        <div>
            头像:
            <input type="file" ref="pic" name="pic">
        </div>
        <button @click="reg">注册</button>
    </div>
</template>

<script>
import  axios  from  "axios";
export default {
        data(){
            return  {
                name:"",
                pass:""
            }
        },
        methods:{
            reg(){
                // 获取普通字段信息
                var { name,pass } = this;
                // 获取文件上传信息
                var files = this.$refs.pic.files[0];
                // console.log(files);
                // 将资源插入到formData对象
                var obj = new  FormData();
                obj.append('name',name);
                obj.append('pass',pass);
                obj.append('pic',files);
                // 实现上传
                axios({
                    url:"http://localhost:3000/reg",
                    method:"post",
                    data:obj,
                    headers:{
                        "Content-Type":"multipart/form-data"
                    },
                    success(res){
                        console.log(res);
                    }
                })

            }
        }
    }
</script>

<style  scoped>

</style>